import axios from "axios";
import * as api from "../../api/gw";
export const uploadImg = function (fileArray) {
    let axiosArr = [];
    fileArray.forEach((item, index) => {
        let formData = new FormData();
        console.log("file", item);
        formData.append("file", item.uri);
        let options = {
            method: "post",
            url: window.api.mall_file_host + api.ImgUpload,
            timeout: 30000,
            data: formData
        }
        // console.log(window.api.mall_file_host + api.ImgUpload);
        axiosArr.push(axios(options));
    });
    return new Promise(async resolve => {
        let resultArray = await axios.all(axiosArr);
        //判断是否所有的请求都成功
        let state = true;
        let data = [];
        for (let item of resultArray) {
            if (item.status !== 200 || item.data.code !== 200) {
                state = false;
                break;
            } else {
                data.push(item.data.visitPath);
            }
        }
        if (state) {
            resolve({
                status: 1,
                data
            });
        } else {
            resolve({
                status: 0,
                data: []
            });
        }
    });
}